package com.xpf.service.status;

import com.xpf.service.status.entity.BpmProcessSuccessEvent;
import com.xpf.service.status.enums.BpmInstanceStatus;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Map;

@Slf4j
@Service
@RequiredArgsConstructor
public class ResultCallbackService extends AbstractResultCallbackService {

    private final StatusServiceFactory statusServiceFactory;

    @Override
    protected void doStatusEvolution(BpmProcessSuccessEvent event) {
        log.info("start-Approval status flow!");
        Map<String, IStatusProcessService<BpmProcessSuccessEvent>> statusProcessServiceMap = statusServiceFactory.openStatusProcess();
        BpmInstanceStatus instanceStatus = event.getSource().getInstanceStatus();
        if (null != instanceStatus) {
            IStatusProcessService<BpmProcessSuccessEvent> statusProcessService = statusProcessServiceMap.get(instanceStatus.name());
            if (null != statusProcessService) {
                //处理状态流转，并调用业务更新
                statusProcessService.statusProcess(event);
                log.info("end-Approval status flow!");
            }
        }
    }

}